/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import com.bayu.services.entity.TStock;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author submonkey
 */
@Repository("tStockDao")
@Transactional
public class TStockDao {

    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly=false)
    public void save(TStock stock) {
        hibernateTemplate.saveOrUpdate(stock);
    }

    @Transactional(readOnly=false)
    public void delete(TStock stock) {
        hibernateTemplate.delete(stock);
    }

    @Transactional(readOnly=false)
    public void update(TStock stock) {
        hibernateTemplate.update(stock);
    }

    public List<TStock> getAll(String query) {
        return hibernateTemplate.find(query);
    }

    public List<TStock> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from TStock where tanggal between '"
            + start + "' and '" + end + "' order by tanggal DESC)");
    }

    public List<TStock> getById(String id) {
        return hibernateTemplate.find("from TStock where id ='"+id+"'");
    }

    public List<TStock> getAllByMonth(String month) {
        return hibernateTemplate.find("from TStock where MONTH(tanggal)='" + month + "order by tanggal ASC" );
    }

    public List custom(String query) {
        return hibernateTemplate.find(query);
    }

    public double getMax() {
        return 0;
    }

    public double getMin() {
        return 0;
    }
}
